@extends('shangcheng.admin.index');

@section('con')

<div style="min-height: 591px;">
	<div class="row">
	    <div class="col-xs-12">
	        <h1 class="page-header">Tables</h1>
	    </div>
	    <!-- /.col-lg-12 -->
	</div>
	<!-- /.row -->
	<div class="row">
	    <div class="col-xs-12">
	        <div class="panel panel-default">
	            <div class="panel-heading">
	                浏览用户
	            </div>
	            <!-- /.panel-heading -->
	            <div class="panel-body">
	                <div class="dataTable_wrapper">
	                    <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
	                    
	                    <form action="{{url('/admin/user/select')}}" method="get">
	                    <div class="row">
	                    <div class="col-sm-6">
	                    <div class="dataTables_length" id="dataTables-example_length"><label>显示<select name="num" aria-controls="dataTables-example" class="form-control input-sm">
	                    
	                    <option value="10" @if($data['num']=='10') selected @endif>10</option>
	                    <option value="25" @if($data['num']=='25') selected @endif>25</option>
	                    <option value="50" @if($data['num']=='50') selected @endif>50</option>
	                    <option value="100" @if($data['num']=='100') selected @endif>100</option>
	                    </select> 条</label></div></div>

	                    <div class="col-sm-6"><div id="dataTables-example_filter" class="dataTables_filter"><label>搜索:<input type="search" class="form-control input-sm"  aria-controls="dataTables-example" name="title" value="{{$data['title'] or ''}}"><button class="btn btn-default">查询</button></label></div></div>
	                    
	                    </div>
	                    </form>

	                    <div class="row"><div class="col-sm-12"><table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info">
	                        <thead>
	                            <tr role="row">
	                            	<th class="sorting_asc" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending" style="width: 5%;">id</th>

	                            	<th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending" style="width: 15%;">用户名</th>
	                            	
	                            	<th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending" style="width: 20%;">邮箱</th>
	                            	
	                            	<th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 10%;" aria-label="Engine version: activate to sort column ascending" >头像</th>

	                            	<th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="width: 10%;">操作</th></tr>
	                        </thead>
	                        <tbody>       
	   								
	   							@foreach($users as $k=>$v)	
	                       		<tr class="gradeA odd" role="row">
	                                <td class="sorting_1">{{$v->id}}</td>
	                                <td>{{$v->name}}</td>
	                                <td>{{$v->email}}</td>
	                                <td class="center"><img src="{{$v->photo}}" width="50px"></td>
	                                <td class="center">
	                                	<a href="{{url('admin/user/update',['id'=>$v->id])}}" class="btn btn-warning btn-xs">修改</a> | <button class="btn btn-danger btn-xs btn-delete">删除</button>
	                                </td>
	                            </tr>
								@endforeach

	                        </tbody>
	                    </table></div></div><div class="row">
	                    	<div class="col-xs-6"><div class="dataTables_info" id="dataTables-example_info" role="status" aria-live="polite">Showing 1 to 10 of 57 entries</div></div>
	                   
	                    <div class="col-xs-6">
	                    	<div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
	                    		
								{!! $users->appends($data)->render() !!}

	                    	</div></div></div></div>
	                </div>
	                <!-- /.table-responsive -->
	                
	            </div>
	            <!-- /.panel-body -->
	        </div>
	        <!-- /.panel -->
	    </div>
	    <!-- /.col-lg-12 -->
	</div>
	<!-- /.row -->
	

</div>

@endsection

@section('js')

<script type="text/javascript">

	$.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
    });

	
	$('.btn-delete').click(function(){

		var id=$(this).parents('tr').find('.sorting_1').text();

		var btn=$(this);

		$.post('/admin/user/delete',{id:id},function(data) {
			
			if(data==1){

				btn.parents('tr').remove();

			}else{

				alert('删除失败');
			}

		})

	})

</script>
@endsection